// Book类
class Book(val title: String, val author: String, val isbn: String, var isBorrowed: Boolean = false)

object Book {
  // apply方法用于创建Book对象
  def apply(title: String, author: String, isbn: String, isBorrowed: Boolean = false): Book = {
    new Book(title, author, isbn, isBorrowed)
  }

  // unapply方法用于提取Book对象的属性
  def unapply(book: Book): Option[(String, String, String, Boolean)] = {
    Some((book.title, book.author, book.isbn, book.isBorrowed))
  }
}

// Library类
class Library {
  private var availableBooks: List[Book] = Nil
  private var borrowedBooks: List[Book] = Nil

  def addBook(book: Book): Unit = {
    availableBooks = book :: availableBooks
    println(s"Book '${book.title}' by ${book.author} with ISBN ${book.isbn} has been added to the library.")
  }

  def borrowBook(isbn: String): Unit = {
    availableBooks.find(_.isbn == isbn) match {
      case Some(book) =>
        availableBooks = availableBooks.filterNot(_ == book)
        borrowedBooks = book :: borrowedBooks
        book.isBorrowed = true
        println(s"Book '${book.title}' by ${book.author} with ISBN ${book.isbn} has been borrowed.")
      case None =>
        println(s"Book with ISBN $isbn is not available in the library.")
    }
  }

  def returnBook(isbn: String): Unit = {
    borrowedBooks.find(_.isbn == isbn) match {
      case Some(book) =>
        borrowedBooks = borrowedBooks.filterNot(_ == book)
        availableBooks = book :: availableBooks
        book.isBorrowed = false
        println(s"Book '${book.title}' by ${book.author} with ISBN ${book.isbn} has been returned.")
      case None =>
        println(s"No book with ISBN $isbn was borrowed from the library.")
    }
  }
}